<?php

namespace api\modules\v1\controllers\marketing;

use Yii;
use api\controllers\OnAuthController;
use common\models\marketing\OutpatientType;
use common\helpers\CommonHelper;

/**
 * Class OutpatientTypeController
 * @package api\modules\v1\controllers\marketing
 */
class OutpatientTypeController extends OnAuthController
{
    /**
     * @var OutpatientType
     */
    public $modelClass = OutpatientType::class;

    /**
     * @api {get} /v1/marketing/outpatient-type/index 就诊类型列表
     * @apiName index
     * @apiGroup OutpatientType
     */
    public function actionIndexOutpatientType()
    {
        // 查询结果
        $data = Yii::$app->services->marketingOutpatientType->getList();

        return $data;
    }

    /**
     * @api {post} /v1/marketing/outpatient-type/create 新增就诊类型
     * @apiName create
     * @apiGroup OutpatientType
     *
     * @apiParam {String} name              就诊类型名称
     * @apiParam {Number} status            【1启用、0停用】
     */
    public function actionCreateOutpatientType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;

        return Yii::$app->services->marketingOutpatientType->create($params);
    }

    /**
     * @api {post} /v1/marketing/outpatient-type/update 编辑就诊类型
     * @apiName update
     * @apiGroup OutpatientType
     *
     * @apiParam {Number} id                就诊类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateOutpatientType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        return Yii::$app->services->marketingOutpatientType->update($params);
    }


    /**
     * @api {post} /v1/marketing/outpatient-type/update-status 编辑就诊类型的状态
     * @apiName update-status
     * @apiGroup OutpatientType
     *
     * @apiParam {Number} id                就诊类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateOutpatientTypeStatus()
    {
        $id = Yii::$app->request->post('id');
        $status = Yii::$app->request->post('status');

        return Yii::$app->services->marketingOutpatientType->updateStatus($id, $status);
    }

    /**
     * @api {post} /v1/marketing/outpatient-type/delete 删除就诊类型
     * @apiName delete
     * @apiGroup OutpatientType
     *
     * @apiParam {Number} id                就诊类型ID
     */
    public function actionDeleteOutpatientType()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->marketingOutpatientType->delete($id);
    }

}